﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ECRMS.WinForm.BaseClass;
using System.Linq;
using ECRMS.WinForm.ModuleEdits;

namespace ECRMS.WinForm.Modules
{
    [ModuleInstance((int)ModuleEnum.员工管理)]
    public partial class EmployeeModule :BaseModule
    {
        public EmployeeModule()
        {
            base.core.CreateWaitDialog("初始化中请稍候...");
            InitializeComponent();
            SuperView();
            base.core.SetWaitDialogCaption("数据载入中...");
            InitData();
            base.core.CloseWaitDialog();
            
        }

        private void SuperView()
        {
            newBarButtonVisiable = false;
        }
        public DataView TutorialDataView { get { return dvTutorial; } }
        DataView dvTutorial = null;
        //List<Tbl_Employee> employeeList = null;
        //List<Tbl_Employee> employeeList1 = null;

        private void InitData()
        {
            layoutControl1.SetDefaultLayout();
            layoutControl2.SetDefaultLayout();

            //官方demo中用dataview做数据载体，然后从xml中读取数据进来，可行
            //GetCarsData(null);
            //dataNavigator1.DataSource = dvTutorial;

            //using (var dataContext=new dbDataContext())
            //{
            //    employeeList = dataContext.GetTable<Tbl_Employee>().ToList();
            //    employeeList1 = dataContext.GetTable<Tbl_Employee>().ToList();
            //}
            ////第一个tab页
            //dataNavigator1.DataSource = employeeList;
            //BindControlItems();
            ////第二个tab页
            //gridControl1.DataSource = employeeList1;
            //BindControlItems1();
        }

        private void BindControlItems()
        {
            //textEdit1.DataBindings.Add(new Binding("Text", employeeList, "Name"));
            //dateEdit1.DataBindings.Add(new Binding("EditValue", employeeList, "Brithday"));
            //memoEdit1.DataBindings.Add(new Binding("Text", employeeList, "LoginName"));
        }

        private void BindControlItems1()
        {
            //labelControl2.DataBindings.Add(new Binding("Text", employeeList1, "Name"));
            //labelControl4.DataBindings.Add(new Binding("Text", employeeList1, "Age"));
        }

        private void GetCarsData(DataSet ds)
        {
            string DBFileName = DevExpress.Utils.FilesHelper.FindingFileName(Application.StartupPath, "Data\\cars.xml");
            if (DBFileName != "")
            {
                if (ds == null) ds = new DataSet();
                ds.ReadXml(DBFileName);
                dvTutorial = ds.Tables[0].DefaultView;
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            OpenEmployeeEditFrom();
        }

        private void OpenEmployeeEditFrom()
        {
            //showdialog类型
            EditForm dlg = new EditForm(this.RectangleToScreen(this.Bounds));
            DialogResult result = dlg.ShowDialog();
            if (result == DialogResult.OK)
            {
                MessageBox.Show("添加成功！");
                return;
            }
            else if (result == DialogResult.Cancel)
            {
                MessageBox.Show("添加失败！");
                return;
            }
            dlg.Dispose();

        }
    }
}
